/**
 * Created by 肖浩容 on 2017/1/7.
 */
import java.sql.*;
import java.util.ArrayList;
import java.util.List;

public class Interface {
    //输入爬取内容到数据库的方法
    public static boolean Insert_sb(String Aid, String Title, String Author, String Tname, int Favorites,Connection connection,PreparedStatement preparedStatement) {

        String sql = "insert into sb(aid,title,author,category,favorite_num) values (?,?,?,?,?)";
        boolean flag = false;
        try {
            preparedStatement = connection.prepareStatement(sql);
            preparedStatement.setString(1, Aid);
            preparedStatement.setString(2, Title);
            preparedStatement.setString(3, Author);
            preparedStatement.setString(4, Tname);
            preparedStatement.setInt(5, Favorites);
            int isOK = preparedStatement.executeUpdate();
            if (isOK > 0) {
                return !flag;
            } else {
                return flag;
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }

        return flag;
    }
    public static List FindHottest(Connection connection,PreparedStatement preparedStatement){
        String[] k = {"鬼畜调教","搞笑","人力VOCALOID","明星","网游·电竞","音MAD","日常","电视剧相关","综合","电影相关","GMV","音乐选集","翻唱","三次元音乐","教程演示","MAD·AMV","MMD·3D","短片·手书·配音","趣味科普人文","单机联机","国产动画","连载动画","完结动画","资讯","官方延伸","广告","音游","综艺","VOCALOID·UTAU","原创音乐","演奏","野生技术协会","OP/ED/OST","宅舞","三次元舞蹈","舞蹈教程","Korea相关","Mugen","纪录片","星海","机械","运动","演讲?公开课","数码","美食圈","动物圈","手工","绘画","美妆","服饰","健身"};
        List hottestAVs=new ArrayList();
        for(int i = 0;i<50;i++){
            String sql = "select * from sb where category like '"+k[i]+"' order by favorite_num desc limit 0,3;";
            try{
                preparedStatement = connection.prepareStatement(sql);
                Statement stmt=connection.createStatement();//创建一个Statement对象
                ResultSet rs=stmt.executeQuery(sql);//执行查询，把查询结果赋值给结果集对象
                String av;
                while(rs.next()){//遍历结果集
                    av=rs.getString("aid");//获得av号
                    //username=rs.getString(2);//
                    //password=rs.getString("password");//
                    //age=rs.getInt(4);//
                    //sex=rs.getInt(5);//
                    //System.out.println(id+"\t"+username+"\t"+password+"\t"+age+"\t"+sex+"\t");
                    hottestAVs.add(av);
                }
            }catch(SQLException e){
                e.printStackTrace();
            }

        }
        return hottestAVs;
    }
}
